<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>

<html>
	<head>
		<title>流程业务启动</title>
		<%@ include file="/common/meta.jsp"%>
		<%@ include file="/common/jquery-ui-inc.jsp"%>
		<script>
//$.messager.defaults={ok:"确定",cancel:"取消"};   
$.ajaxSetup({
	cache:false
})
$(function() {
	$('#lockList').datagrid( {
		title : '流程定义',
		url : '${ctx}/flow/core/flow-deploy!data.action',
		loadMsg : '数据载入中，请稍后……',
		nowrap : false,
		collapsible : false,
		fitColumns : true,
		pagination : true,
		singleSelect : true,
		rownumbers : true,
		remoteSort : false,
		pageList : [ 15, 30, 50 ],
		idField : 'id',
		columns : [ [ {
			field : 'id',
			title : '序号',
			width : 200,
			sorter : function(a, b) {
				return (a > b ? 1 : -1);
			}
		}, {
			field : 'name',
			title : '流程名',
			width : 140,
			sorter : function(a, b) {
				return (a > b ? 1 : -1);
			}
		}, {
			title : '流程版本',
			field : 'version',
			width : 100
		}, {
			title : '流程key',
			field : 'key',
			width : 200
		}, {
			title : '流程发布Id',
			field : 'deploymentId',
			width : 200
		}, {
			title : '流程描述',
			field : 'description',
			width : 200
		}, {
			title : '流程状态',
			field : 'state',
			width : 100,
			formatter: function(val, rec,rowIndex){
				if(val == 'suspended')return "<span style='color:red;'>已挂起</span>";
				if(val == 'active')return "<span style='color:green;'>正常</span>";
			}
		}, {
			title : '流程操作',
			field : 'cz',
			width : 200,
			formatter:function(value,row,index){
			 	return '<a href="javascript:strarProcess(\''+row.id+'\',\''+row.state+'\')">启动</a> ';
			}
		}] ]

		});
});
	function closeBusProcessWin(){
		$('#startProcessWin').window('close');
	}
	
	function strarProcess(id,state){
		if(state=="suspended"){
			$.messager.alert('提示',"该流程处于挂起状态,请先恢复后再启动！", 'warning');
			return ;
		}else{
			$("#startProcessWin").window('open');
			$("#definitionId").val(id);
		}
		
	}
	
	//启动流程定义
	function strarProcessOk() {
		//alert(id)
		var id = $("#definitionId").val();
		var params = $("#params").val();
		$.ajax({
			type : "post",
			url : "${ctx}/flow/core/flow-test!start.action?definitionId="+ id,
			dataType:'json',
			data:params,
			beforeSend : function(XMLHttpRequest) {
			},
			success : function(data, textStatus) {
				var f = data.flag;
				if(f == "T"){
					$.messager.alert('结果', data.msg, 'info',function(){
						reload();
					});
				}else{
					$.messager.alert('错误', data.msg, 'error');
				}
			},
			complete : function(XMLHttpRequest, textStatus) {
				closeBusProcessWin();
				//HideLoading();
			},
			error : function() {
				//请求出错处理
			}
		});
	}
	
	//恢复流程定义
	function resume(id){
		$.ajax({
			type : "post",
			url : "${ctx}/flow/core/flow-deploy!resume.action?deploymentId="+ id,
			dataType:'json',
			beforeSend : function(XMLHttpRequest) {
			},
			success : function(data, textStatus) {
				var f = data.flag;
				if(f == "T"){
					$.messager.alert('结果', data.msg, 'info',function(){
						reload();
					});
				}else{
					$.messager.alert('错误', data.msg, 'error');
				}
			},
			complete : function(XMLHttpRequest, textStatus) {
			},
			error : function() {
				//请求出错处理
			}
		});
	}

	function closeStartProWin(){
		$('#startProcessWin').window('close');
	}

	function reload(){
		$('#lockList').datagrid('reload');
	}

		
	function lockQuery(){					
	    var queryParams = $('#lockList').datagrid('options').queryParams;
	      queryParams.lockCname = $('#lockCname').val();
	      queryParams.lockPath = $('#lockPath').val();
	      queryParams.actFullEname =$('#actFullEname').val();
	      queryParams.lockStatus = $('#lockStatus').val();
	      reload(); 
	  }
	function clearQuery(){					
	    $('#lockCname').val('');
	    $('#lockPath').val('');
	    $('#actFullEname').val('');
	    lockQuery(); 
	  }  
	  
			
	</script>
	</head>

	<body>
		<table id="lockList"></table>
		
		<div id="startProcessWin" class="easyui-window" title="启动流程"
			style="padding: 5px; width: 330px; height:150px;"
			iconCls="icon-search" closed="true" maximizable="false"
			minimizable="false" collapsible="false" modal="true">
			<div class="easyui-layout" fit="true" border="false">
				<div region="center">
				<table class="datagrid-body">
					<tr>
						<td class="datagrid-header">
							流程定义Id
						</td>
						<td>
							<input name="definitionId" id="definitionId" readonly="readonly"/>
						</td>
					</tr>
					
					<tr>
						<td class="datagrid-header">
							流程启动参数
						</td>
						<td>
							<input name="params" id="params" value=""/>
						</td>
					</tr>
					<tr>
						<td>
							<a class="easyui-linkbutton" iconCls="icon-add"
								onclick="strarProcessOk();">启动流程</a>
						</td>
						<td>
							<a class="easyui-linkbutton" iconCls="icon-cancel" onclick="closeStartProWin();">取消</a>
						</td>
					</tr>
				</table>
				</div>
			</div>
		</div>

	</body>
</html>